﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Portal.Ef.Repository
{
    public abstract class Repository<T, TR, TM> : IRepository<T>
    {


        internal Entities Entities;

        protected Repository()
        {

            Entities = EntitiesFactory.Entities();
        }

        public abstract T CreateEntity();

        public abstract IQueryable<T> MapQueryable(IQueryable<TM> queryable);
        public abstract IQueryable<TM> ReverseMapQueryable(IQueryable<T> queryable);
        public abstract T MapModel(TM model);
        public abstract TM ReverseMapModel(T queryable);


        public abstract IQueryable<T> Get();


        public abstract long Count();


        public abstract IQueryable<T> Get(Expression<Func<T, bool>> expression);


        public abstract IQueryable<T> GetSort(string sort = "Id", string order = "DESC");


        public abstract IQueryable<T> GetSort(Expression<Func<T, bool>> expression, string sort = "Id", string order = "DESC");


        public abstract void Add(T t);


        public abstract void Update(T t);


        public abstract void AddOrUpdate(T t);



        public abstract void Delete(T t);



        public abstract void Delete(Expression<Func<T, bool>> expression);

        public abstract void Save();

    }
}
